package leetcode20211003;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LUYAO
 * Date: 2021-10-03
 * Time: 21:00
 */
public class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode(int x) { val = x; }
}

//二叉树的镜像
class Solution1 {
    public TreeNode mirrorTree(TreeNode root) {
        if(root == null) return null;
        TreeNode tempright = mirrorTree(root.right);
        TreeNode templeft = mirrorTree(root.left);

        root.left = tempright;
        root.right = templeft;

        return root;
    }
}

//判断B是不是A的子结构
class Solution2 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        return (A != null && B != null) && (recur(A, B) || isSubStructure(A.left, B) || isSubStructure(A.right, B));

    }

    public boolean recur(TreeNode A, TreeNode B){
        if(B == null) return true;
        if(A == null || A.val != B.val) return false;
        return recur(A.left,B.left) && recur(A.right, B.right);
    }
}

//判断是不是镜像二叉树
class Solution3 {
    public boolean isSymmetric(TreeNode root) {
        return root == null ? true : recur(root.left, root.right);

    }

    boolean recur(TreeNode L, TreeNode R) {
        if(L == null && R == null) return true;
        if(L == null || R == null || L.val != R.val) return false;
        return recur(L.left, R.right) && recur(L.right, R.left);
    }


}
